import aiball.UserAccount;
import aiball.UserAccountUserRoles;
import aiball.UserRoles;


class BootStrap {
	
	def springSecurityService
	
	
    def init = { servletContext ->
		
		def userRole = UserRoles.findByAuthority('ROLE_USER') ?: new UserRoles(authority: 'ROLE_USER').save(failOnError: true)
		def adminRole = UserRoles.findByAuthority('ROLE_ADMIN') ?: new UserRoles(authority: 'ROLE_ADMIN').save(failOnError: true)
	   
		
		def adminUser = UserAccount.findByUsername('admin') ?: new UserAccount(
			username: 'admin',
			password: 'admin',
			enabled: true).save(failOnError: true)

			
			
			if (!adminUser.authorities.contains(adminRole)) {
				UserAccountUserRoles.create adminUser, adminRole
			}

		
    }
    def destroy = {
    }
}
